package com.example.demo.information.repository;

import com.example.demo.information.entity.Bjxx;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author littlecar
 * @date 2020/3/23 15:18
 */
@Repository
public interface BjxxRepository extends JpaRepository<Bjxx, Long> {

    List<Bjxx> findByNameLike(String name);

    @Query(nativeQuery = true, value = " select s.* from bjxx s where s.name like ?1 order by s.id limit ?2,?3")
    List<Bjxx> findPageByNameLike(String name, int pages, Integer limit);

    @Query(nativeQuery = true, value = " select s.* from bjxx s order by s.id limit ?1,?2")
    List<Bjxx> findPageAll(int pages, Integer limit);

    List<Bjxx> findByName(String name);

    List<Bjxx> findByBjbh(String bjbh);

    @Query(nativeQuery = true,value = " select b.* from bjxx b where exists(select null from school_bjxx s where s.school_id=?1 and s.bjxx_id=b.id) and b.bzr_id=?2")
    List<Bjxx> findBySchoolIdAndBzrId(Long school_id, Long old_bzrId);
}
